package com.pw.study.utils

import org.apache.spark.sql.SparkSession
import org.apache.spark.{SparkConf, SparkContext}

/**
 * @Desc: TODO
 * @author: future
 * @since: 2022/6/13-20:45
 */
object SparkUtils {
  /**
   * sql环境
   *
   * @param appName
   */
  def getEnvBySql(appName: String): SparkSession = {
    val conf = new SparkConf().setAppName(appName).setMaster("local[4]").set("spark.testing.memory", "4718592000")
    val spark: SparkSession = SparkSession.builder().config(conf).getOrCreate()
    spark.sparkContext.setLogLevel("error")
    spark
  }

  def getEnv(appName: String): SparkContext = {
    val conf: SparkConf = new SparkConf().setAppName(appName).setMaster("local[*]")
    val sc: SparkContext = new SparkContext(conf)
    sc.setLogLevel("error")
    sc
  }

}
